home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / vertex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  5.3 KB  |  197 lines

  1. /* $Id: vertex.c,v 1.4 1996/12/18 20:00:57 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.0
  6.  * Copyright (C) 1995-1996  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: vertex.c,v $
  26.  * Revision 1.4  1996/12/18 20:00:57  brianp
  27.  * gl_set_material() now takes a bitmask instead of face and pname
  28.  *
  29.  * Revision 1.3  1996/12/07 10:21:28  brianp
  30.  * call gl_set_material() instead of gl_Materialfv()
  31.  *
  32.  * Revision 1.2  1996/09/15 14:19:16  brianp
  33.  * now use GLframebuffer and GLvisual
  34.  *
  35.  * Revision 1.1  1996/09/13 01:38:16  brianp
  36.  * Initial revision
  37.  *
  38.  */
  39.  
  40.  
  41. #include <assert.h>
  42. #include "draw.h"
  43. #include "light.h"
  44. #include "dlist.h"
  45. #include "macros.h"
  46. #include "types.h"
  47. #include "vb.h"
  48. #include "vertex.h"
  49.  
  50.  
  51.  
  52. #ifdef DEBUG
  53. #  define ASSERT(X)  assert(X)
  54. #else
  55. #  define ASSERT(X)
  56. #endif
  57.  
  58.  
  59.  
  60. void gl_Normal3f( GLcontext *ctx, GLfloat nx, GLfloat ny, GLfloat nz )
  61. {
  62.    ctx->Current.Normal[0] = nx;
  63.    ctx->Current.Normal[1] = ny;
  64.    ctx->Current.Normal[2] = nz;
  65. }
  66.  
  67.  
  68.  
  69. void gl_Normal3fv( GLcontext *ctx, const GLfloat *n )
  70. {
  71.    ctx->Current.Normal[0] = n[0];
  72.    ctx->Current.Normal[1] = n[1];
  73.    ctx->Current.Normal[2] = n[2];
  74. }
  75.  
  76.  
  77.  
  78.  
  79. void gl_Indexf( GLcontext *ctx, GLfloat c )
  80. {
  81.    ctx->Current.Index = (GLuint) (GLint) c;
  82.    ctx->VB->MonoColor = GL_FALSE;
  83. }
  84.  
  85.  
  86. void gl_Indexi( GLcontext *ctx, GLint c )
  87. {
  88.    ctx->Current.Index = (GLuint) c;
  89.    ctx->VB->MonoColor = GL_FALSE;
  90. }
  91.  
  92.  
  93.  
  94.  
  95. void gl_Color4f( GLcontext *ctx,
  96.                  GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
  97. {
  98.    ctx->Current.IntColor[0] = red   * ctx->Visual->RedScale;
  99.    ctx->Current.IntColor[1] = green * ctx->Visual->GreenScale;
  100.    ctx->Current.IntColor[2] = blue  * ctx->Visual->BlueScale;
  101.    ctx->Current.IntColor[3] = alpha * ctx->Visual->AlphaScale;
  102.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  103.    ctx->VB->MonoColor = GL_FALSE;
  104. }
  105.  
  106.  
  107.  
  108. /* glColor() which modifies (a) material(s) */
  109. void gl_ColorMat4f( GLcontext *ctx,
  110.                     GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
  111. {
  112.    GLfloat color[4];
  113.    ctx->Current.IntColor[0] = red   * ctx->Visual->RedScale;
  114.    ctx->Current.IntColor[1] = green * ctx->Visual->GreenScale;
  115.    ctx->Current.IntColor[2] = blue  * ctx->Visual->BlueScale;
  116.    ctx->Current.IntColor[3] = alpha * ctx->Visual->AlphaScale;
  117.    /* update material */
  118.    ASSERT( ctx->Light.ColorMaterialEnabled );
  119.    ASSIGN_4V( color, red, green, blue, alpha );
  120.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  121.    ctx->VB->MonoColor = GL_FALSE;
  122. }
  123.  
  124.  
  125.  
  126. /*
  127.  * Used when colors are not scaled to [0,255]
  128.  */
  129. void gl_Color4ub( GLcontext *ctx,
  130.                   GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
  131. {
  132.    ctx->Current.IntColor[0] = red   * ctx->Visual->RedScale   * (1.0F/255.0F);
  133.    ctx->Current.IntColor[1] = green * ctx->Visual->GreenScale * (1.0F/255.0F);
  134.    ctx->Current.IntColor[2] = blue  * ctx->Visual->BlueScale  * (1.0F/255.0F);
  135.    ctx->Current.IntColor[3] = alpha * ctx->Visual->AlphaScale * (1.0F/255.0F);
  136.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  137.    ctx->VB->MonoColor = GL_FALSE;
  138. }
  139.  
  140.  
  141. /*
  142.  * Used when colors are scaled to [0,255].
  143.  */
  144. void gl_Color4ub8bit( GLcontext *ctx,
  145.                       GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
  146. {
  147.    ASSIGN_4V( ctx->Current.IntColor, red, green, blue, alpha );
  148.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  149.    ctx->VB->MonoColor = GL_FALSE;
  150. }
  151.  
  152.  
  153.  
  154. /* glColor() which modifies (a) material(s) */
  155. void gl_ColorMat4ub( GLcontext *ctx,
  156.                      GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
  157. {
  158.    GLfloat color[4];
  159.    if (ctx->Visual->EightBitColor) {
  160.       ASSIGN_4V( ctx->Current.IntColor, red, green, blue, alpha );
  161.    }
  162.    else {
  163.       ctx->Current.IntColor[0] = red   * ctx->Visual->RedScale   * (1.0F/255.0F);
  164.       ctx->Current.IntColor[1] = green * ctx->Visual->GreenScale * (1.0F/255.0F);
  165.       ctx->Current.IntColor[2] = blue  * ctx->Visual->BlueScale  * (1.0F/255.0F);
  166.       ctx->Current.IntColor[3] = alpha * ctx->Visual->AlphaScale * (1.0F/255.0F);
  167.    }
  168.    /* update material */
  169.    ASSERT( ctx->Light.ColorMaterialEnabled );
  170.    color[0] = red   * (1.0F/255.0F);
  171.    color[1] = green * (1.0F/255.0F);
  172.    color[2] = blue  * (1.0F/255.0F);
  173.    color[3] = alpha * (1.0F/255.0F);
  174.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  175.    ctx->VB->MonoColor = GL_FALSE;
  176. }
  177.  
  178.  
  179.  
  180.  
  181. void gl_TexCoord4f( GLcontext *ctx,
  182.                     GLfloat s, GLfloat t, GLfloat r, GLfloat q )
  183. {
  184.    ctx->Current.TexCoord[0] = s;
  185.    ctx->Current.TexCoord[1] = t;
  186.    ctx->Current.TexCoord[2] = r;
  187.    ctx->Current.TexCoord[3] = q;
  188. }
  189.  
  190.  
  191.  
  192. void gl_EdgeFlag( GLcontext *ctx, GLboolean flag )
  193. {
  194.    ctx->Current.EdgeFlag = flag;
  195. }
  196.  
  197.